//
//  HOTNaviViewController.m
//  Genpara
//
//  Created by AndyChang.zhang on 14-8-27.
//  Copyright (c) 2014年 zhangchh. All rights reserved.
//

#import "HOTNavigationViewController.h"
#import "HOTNaviBar.h"
#import "HOTBaseViewController.h"

@interface HOTNavigationViewController () <UINavigationControllerDelegate>

@end

@implementation HOTNavigationViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.delegate = self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass {
    
    if ( self = [super initWithNavigationBarClass:navigationBarClass toolbarClass:toolbarClass]) {
        
        
        return self;
    }
    
    return nil;
}

+(instancetype)createNaviWithRootViewController:(UIViewController *)rootViewController {
    
    HOTNavigationViewController *navi = [[[self class] alloc]
                                         initWithNavigationBarClass:[HOTNaviBar class]
                                         toolbarClass:nil];
    
    [navi pushViewController:rootViewController animated:NO];
    
    return navi;
}

-(UIViewController *)popViewControllerAnimated:(BOOL)animated {
    
    if (self.viewControllers.count > 1) {
        
        UIViewController *popVc = [self.viewControllers objectAtIndex:self.viewControllers.count-2];
        UIViewController *topVc = [self topViewController];
        if ([popVc isKindOfClass:[HOTBaseViewController class]]) {
            
            if ([popVc respondsToSelector:@selector(afterPopWithViewController:)]
                && [topVc isKindOfClass:[HOTBaseViewController class]]
                && ((HOTBaseViewController *)topVc).popVcExcute) {
                
                [((HOTBaseViewController *)popVc) afterPopWithViewController:topVc];
            }
        }
    }
    
    return  [super popViewControllerAnimated:animated];
}


#pragma mark - 私有方法

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
